package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.danmo.domain.DanmoPrintingWorks;
import com.muyu.danmo.service.IDanmoPrintingWorksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 印刷出版作品Controller
 *
 * @author yangle
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/printingWorks")
public class DanmoPrintingWorksController extends BaseController
{
    @Autowired
    private IDanmoPrintingWorksService danmoPrintingWorksService;

    /**
     * 查询印刷出版作品列表
     */
//    @RequiresPermissions("system:printingWorks:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoPrintingWorks>> list(DanmoPrintingWorks danmoPrintingWorks)
    {
        startPage();
        List<DanmoPrintingWorks> list = danmoPrintingWorksService.selectDanmoPrintingWorksList(danmoPrintingWorks);
        return getDataTable(list);
    }

    /**
     * 导出印刷出版作品列表
     */
//    @RequiresPermissions("system:printingWorks:export")
    @Log(title = "印刷出版作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoPrintingWorks danmoPrintingWorks)
    {
        List<DanmoPrintingWorks> list = danmoPrintingWorksService.selectDanmoPrintingWorksList(danmoPrintingWorks);
        ExcelUtil<DanmoPrintingWorks> util = new ExcelUtil<DanmoPrintingWorks>(DanmoPrintingWorks.class);
        util.exportExcel(response, list, "印刷出版作品数据");
    }

    /**
     * 获取印刷出版作品详细信息
     */
//    @RequiresPermissions("system:printingWorks:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoPrintingWorksService.selectDanmoPrintingWorksById(id));
    }

    /**
     * 新增印刷出版作品
     */
//    @RequiresPermissions("system:printingWorks:add")
    @Log(title = "印刷出版作品", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoPrintingWorks danmoPrintingWorks)
    {
        return toAjax(danmoPrintingWorksService.insertDanmoPrintingWorks(danmoPrintingWorks));
    }

    /**
     * 修改印刷出版作品
     */
//    @RequiresPermissions("system:printingWorks:edit")
    @Log(title = "印刷出版作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoPrintingWorks danmoPrintingWorks)
    {
        return toAjax(danmoPrintingWorksService.updateDanmoPrintingWorks(danmoPrintingWorks));
    }

    /**
     * 删除印刷出版作品
     */
//    @RequiresPermissions("system:printingWorks:remove")
    @Log(title = "印刷出版作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoPrintingWorksService.deleteDanmoPrintingWorksByIds(ids));
    }
}
